package cn.hywx.convert;

import cn.hywx.convert.beans.DocumentBean;

/**
 * office comsumer for convert
 * @author all3n
 *
 */
public class OfficeConsumer implements Runnable{
	private OfficeQueue queue;
	private boolean runFlag = true;
	private static long CONSUMER_DELAY = 1000;
	
	public OfficeConsumer(OfficeQueue q){
		this.queue = q;
	}
	
	@Override
	public void run() {
		while(runFlag){
			int size = queue.convertQueueSize();
			if(size>0){
				try {
					DocumentBean bean = queue.popDocument();
					//convert 
					
					
					
					//convert finished update flag
					DocumentBean.changeState(bean.getId(), DocumentBean.STATE_CONVERTED);
					
					
					System.out.println("consumer："+bean);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			try {
				Thread.sleep(CONSUMER_DELAY);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
